import pandas as pd
from app import app
from models import db, User, Question
from werkzeug.security import generate_password_hash

with app.app_context():
    db.create_all()
    # 导入单词库
    df = pd.read_csv('words.csv')
    for _, row in df.iterrows():
        if not Question.query.filter_by(word=row['word']).first():
            q = Question(word=row['word'], meaning=row['meaning'], level=row['level'])
            db.session.add(q)
    # 创建教师账号
    if not User.query.filter_by(username='teacher').first():
        teacher = User(username='teacher', password=generate_password_hash('123456'), role='teacher')
        db.session.add(teacher)
    db.session.commit()
    print('数据库初始化完成') 